﻿
#include <gcroot.h>
using System::IDisposable;
using osi::root::lock::slimlock::islimlock;

namespace osi { namespace root { namespace lock
{
    public class native_reference
    {
    public:
        gcroot<islimlock^> ref;
        native_reference(islimlock^% i) : ref(i) { }
    };

	public ref struct autolock : public IDisposable
    {
	private:
        native_reference* ref;
	public:
		autolock(islimlock^% i) : ref(new native_reference(i))
		{
			i->wait();
		}

		~autolock()
		{
            this->!autolock();
		}

        !autolock()
        {
            ref->ref->release();
            delete ref;
        }
    };
} } }

